﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Flame.Base
{
    public class DlrPlugin : Attribute
    {
        public DlrPlugin()
        {

        }
    }

    public static class DlrPluginLoader
    {
        public static void LoadAll(string path)
        {

            if (!Directory.Exists(path)) return;
            foreach (string f in Directory.EnumerateFiles(path, "*.dll"))
            {
                try
                {
                var a = Assembly.LoadFrom(f);
                    foreach (Type t in a.GetTypes())
                    {
                        if (t.IsDefined(typeof(DlrPlugin), false))
                            t.InvokeMember("Load", BindingFlags.InvokeMethod, null, null, null);
                    }
                }
                catch
                {
                    FileInfo fi = new FileInfo(f);
                    string destfile = Flame.Dlr.PathsHelper.GetExePath(fi.Name);
                    if (!File.Exists(destfile)) File.Copy(f, destfile);
                }
            }
        }
    }
}
